package com.oauth.twitter.client.ui.handler;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.oauth.components.client.rpc.OAuthAsnyCallBack;
import com.oauth.twitter.client.beans.Tweet;
import com.oauth.twitter.client.rpc.TwitterRemoteServiceAsync;
import com.oauth.twitter.client.ui.TweetsPanel;

public class StatusUpdateHandler implements ValueChangeHandler<String> {

	private TwitterRemoteServiceAsync mService;

	private TweetsPanel mTweetsPanel;

	public StatusUpdateHandler(TwitterRemoteServiceAsync pService, TweetsPanel pTweetsPanel) {
		mService = pService;
		mTweetsPanel = pTweetsPanel;
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> pEvent) {
		mService.updateTweet(pEvent.getValue(), new OAuthAsnyCallBack<Tweet>() {

			@Override
			public void onSuccess(Tweet result) {
				mTweetsPanel.addTweet(result, true);
			}
		});
	}
}
